package c.h.a.w.m;

import android.annotation.SuppressLint;
import android.util.Pair;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import b.b.c.f;
import c.h.a.w.e;
import c.h.a.w.k.e.b;
import com.liuzh.deviceinfo.DeviceInfoApp;
import java.io.File;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

/* compiled from: RepeatFileFloatingView */
public class j implements Runnable {
    public final /* synthetic */ TextView a;
    public final /* synthetic */ ProgressBar b;
    public final /* synthetic */ f c;
    public final /* synthetic */ g d;

    /* compiled from: RepeatFileFloatingView */
    public class a {
        public int a = 0;
        public final /* synthetic */ List b;

        /* compiled from: RepeatFileFloatingView */
        public class a implements Runnable {
            public final /* synthetic */ List a;
            public final /* synthetic */ List b;

            public a(List list, List list2) {
                this.a = list;
                this.b = list2;
            }

            public void run() {
                f fVar = j.this.c;
                if (fVar != null && fVar.isShowing()) {
                    j.this.c.dismiss();
                }
                DeviceInfoApp deviceInfoApp = DeviceInfoApp.c;
                r2 = new Object[2];
                boolean z = false;
                r2[0] = Integer.valueOf(this.a.size());
                r2[1] = Integer.valueOf(this.b.size());
                Toast.makeText(deviceInfoApp, deviceInfoApp.getString(2131689789, r2), 1).show();
                j.this.d.f.a.b();
                j.this.d.c();
                g gVar = j.this.d;
                View findViewById = gVar.findViewById(2131296452);
                if (gVar.i != 0) {
                    z = true;
                }
                findViewById.setEnabled(z);
            }
        }

        public a(List list) {
            this.b = list;
        }

        public final boolean a(e eVar, HashSet<String> hashSet) {
            if (eVar == null || hashSet.contains(eVar.b())) {
                return false;
            }
            eVar.a(0, true);
            return true;
        }

        public void b(List<String> list, List<String> list2) {
            HashSet hashSet = new HashSet(list2);
            int size = this.b.size() - 1;
            while (true) {
                int i = 0;
                if (size >= 0) {
                    Pair pair = (Pair) this.b.get(size);
                    ((b) pair.second).g();
                    b bVar = (b) pair.second;
                    if (bVar.e == -1) {
                        Iterator it = bVar.a.iterator();
                        int indexOf = j.this.d.e.indexOf(pair.second);
                        ArrayList arrayList = new ArrayList(((b) pair.second).a.size());
                        while (it.hasNext()) {
                            if (a((e) it.next(), hashSet)) {
                                arrayList.add(Integer.valueOf((indexOf + i) + 1));
                                it.remove();
                            }
                            i++;
                        }
                        if (((b) pair.second).c.a) {
                            for (i = arrayList.size() - 1; i >= 0; i--) {
                                j.this.d.e.remove(((Integer) arrayList.get(i)).intValue());
                            }
                        }
                        if (((b) pair.second).a.isEmpty()) {
                            j.this.d.e.remove(((Integer) pair.first).intValue());
                        }
                    } else if (a(bVar.b(), hashSet)) {
                        i = ((Integer) pair.first).intValue();
                        j.this.d.e.remove(i);
                        while (true) {
                            int i2 = i - 1;
                            if (i <= -1) {
                                break;
                            }
                            b bVar2 = (b) j.this.d.e.get(i2);
                            if (bVar2.e == -1) {
                                bVar2.a.remove(((b) pair.second).e);
                                List list3 = bVar2.h;
                                if (list3 != null) {
                                    list3.remove(((b) pair.second).e);
                                }
                                bVar2.g();
                                if (bVar2.a.isEmpty()) {
                                    j.this.d.e.remove(bVar2);
                                }
                            } else {
                                i = i2;
                            }
                        }
                    }
                    size--;
                } else {
                    g gVar = j.this.d;
                    gVar.i -= list.size();
                    gVar = j.this.d;
                    gVar.i = Math.max(gVar.i, 0);
                    j.this.d.j.post(new a(list, list2));
                    return;
                }
            }
        }

        @SuppressLint({"SetTextI18n"})
        public void c(Object obj) {
            String str = (String) obj;
            j.this.d.j.post(new i(this));
        }
    }

    public j(g gVar, TextView textView, ProgressBar progressBar, f fVar) {
        this.d = gVar;
        this.a = textView;
        this.b = progressBar;
        this.c = fVar;
    }

    public void run() {
        ArrayList arrayList = new ArrayList(this.d.i);
        ArrayList arrayList2 = new ArrayList(this.d.i);
        int i = 0;
        while (i < this.d.e.size()) {
            b bVar = (b) this.d.e.get(i);
            if (bVar.d()) {
                arrayList2.add(new Pair(Integer.valueOf(i), bVar));
                if (bVar.e < 0) {
                    for (e b : bVar.a) {
                        arrayList.add(b.b());
                    }
                    if (bVar.c.a) {
                        i += bVar.a() + 1;
                    }
                } else {
                    arrayList.add(bVar.b().b());
                }
            }
            i++;
        }
        a aVar = new a(arrayList2);
        String[] strArr = c.h.a.m0.j.a;
        LinkedList linkedList = new LinkedList();
        LinkedList linkedList2 = new LinkedList();
        Iterator it = arrayList.iterator();
        while (it.hasNext()) {
            String str = (String) it.next();
            File file = new File(str);
            if (file.exists()) {
                aVar.c(str);
                if (c.h.a.m0.j.a(file)) {
                    linkedList2.add(str);
                } else {
                    linkedList.add(str);
                }
            }
        }
        aVar.b(linkedList2, linkedList);
    }
}
